/**
 *
 */
package com.neiquan.secondhand.controller;

import com.neiquan.backstage.core.Factor;
import com.neiquan.backstage.core.bsc.impl.BasePersistentServiceImpl;
import com.neiquan.secondhand.po.User;
import com.neiquan.secondhand.util.NqStringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author luochenxi
 * @date 2016-6-12 下午01:33:05
 * @descript 约伴control控制
 */
@Controller
public class RegController extends BasePersistentServiceImpl{

	/**
	 * 页面跳转
	 * @return
     */
	@RequestMapping(value="/reg")
	public String Reg(){
		return "reg";
	}

	/**
	 * 注册
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="regin",method = RequestMethod.POST)
	public String RegIn(HttpServletRequest request){
		String username = request.getParameter("username");
		String phone = request.getParameter("phone");
		String code = request.getParameter("code");
		String password = request.getParameter("password");
		User user =getUnique(User.class, Factor.create("telephone", Factor.C.Eq, phone));
		User user1 = new User();
		if(user==null){
			user1.setAccount(username);
			user1.setTelephone(phone);
			user1.setPassword(NqStringUtils.md5Base64(password));
			user1.setIsDelte(0);
			user1.setFlag(0);
			create(user1);
			return "success";
		}else {
			return "fail";
		}

	}


}

